Serve the root index.html for all client-side routes when hosted in Netlify or GitLab Pages#11356
Open
nfriend wants to merge 1 commit into
Open
Serve the root index.html for all client-side routes when hosted in Netlify or GitLab Pages#11356nfriend wants to merge 1 commit into
nfriend wants to merge 1 commit into
Conversation
|
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
_redirectsfile that allows client-sidepushStaterouting to work out of the box when deployed on Netlify or GitLab Pages.More details about the
_redirectsfile can be found here. Here's a section about this specific setup.Relevant
create-react-appdocshttps://create-react-app.dev/docs/deployment#serving-apps-with-client-side-routing
How to test
Create a new GitHub repo
Scaffold a new project using this PR's branch of
create-react-appCommit and push
Using a Netlify account, connect Netlify to the new GitHub repo created in step #1
Use the default Netlify options to deploy the site
Verify that all URL routes result in the root

index.htmlbeing served. For example, navigating tohttps://your-netlify-app-here.netlify.app/a/client/side/routeshould look like this:In contrast, without the
_redirectsfile, Netlify would serve up a 404 page:The process for testing on GitLab Pages is similar, although it involves a few extra steps (setting up a
.gitlab-ci.ymlpipeline to publish a Pages site).